package com.shujia.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class Code04FileDownLoad {
    public static void main(String[] args) throws URISyntaxException, IOException {

        Configuration conf = new Configuration();

        URI uri = new URI("hdfs://master:9000");
        // 通过连接获取其操作对象
        FileSystem fileSystem = FileSystem.get(uri, conf);
        // 具体子实现类为 org.apache.hadoop.hdfs.DistributedFileSystem

        boolean exists = fileSystem.exists(new Path("/data/bbb.txt"));
        if(exists){
            fileSystem.copyToLocalFile(new Path("/data/bbb.txt"),new Path("data/bbb.txt"));
        }

        // 关闭连接
        fileSystem.close();
    }
}
